package com.googlecode.guicespring;

import org.springframework.beans.factory.FactoryBean;
import org.springframework.util.Assert;

import com.google.inject.Injector;

public class GuiceFactoryBean implements FactoryBean {
	
	private Injector injector;
	
	private Class<?> objectType;

	public GuiceFactoryBean(Injector injector, Class<?> objectType) {
		Assert.notNull(injector, "injector required");
		Assert.notNull(objectType, "objectType required");
		this.injector = injector;
		this.objectType = objectType;
	}

	@Override
	public Object getObject() throws Exception {
		return injector.getInstance(objectType);
	}

	@Override
	public Class<?> getObjectType() {
		return objectType;
	}

	@Override
	public boolean isSingleton() {
		return true;
	}


}
